﻿/*******************************************************************
 *     JameE
 *******************************************************************
  Copyright 2010 Clifford Champion and JameE contributors.
  
  This file is part of JameE.
  
  JameE is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  JameE is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with JameE.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************/
 
/// <reference path="../Base/Classer.js" />
/// <reference path="../Base/IncludeLoader.js" />

$class_static(
"JameE.Math.Algorithms",
{
	/////////////////////
	// CONSTANTS
	/////////////


	/////////////////////
	// FIELDS
	/////////////


	/////////////////////
	// CONSTRUCTORS
	/////////////
	_ctor: function () {
	},


	/////////////////////
	// METHODS
	/////////////
	maximalRectangle: function (fSWidth, fSHeight, fDWidth, fDHeight) {
		/// <summary>Returns the largest possible dimensions that
		/// fits within the destination dimensions and preserves
		/// the aspect ratio of the source rectangle.</summary>

		$require_type(fSWidth, "number");
		$require_type(fSHeight, "number");
		$require_type(fDWidth, "number");
		$require_type(fDHeight, "number");

		var fSourceAR = fSWidth / fSHeight;

		var fNewWidth;
		var fNewHeight;

		// try to maximize width
		fNewWidth = fDWidth;
		fNewHeight = fNewWidth / fSourceAR;

		// check
		if (fNewHeight <= fDHeight) {
			return new $vector3(fNewWidth, fNewHeight);
		}

		// constraints were broken. we are bounded by height
		fNewHeight = fDHeight;
		fNewWidth = fSourceAR * fNewHeight;
		return new $vector3(fNewWidth, fNewHeight);
	}
});

$include_notify("Math/Algorithms.js");

